<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>巡检任务管理制定与分配</title>
    <!-- BOOTSTRAP STYLES-->
    <link href="../assets/css/bootstrap.css" rel="stylesheet"/>
    <!-- FONTAWESOME STYLES-->
    <link href="../assets/css/font-awesome.css" rel="stylesheet"/>
    <!--CUSTOM BASIC STYLES-->
    <link href="../assets/css/basic.css" rel="stylesheet"/>
    <!--CUSTOM MAIN STYLES-->
    <link href="../assets/css/custom.css" rel="stylesheet"/>
    <!-- GOOGLE FONTS-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
</head>
<body>
<div id="wrapper">
    <div id="page-inner">
        <div class="row">
            <div class="col-md-12">
                <h4 class="page-subhead-line">巡检任务管理 >> 制定与分配</h4>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <!--   Kitchen Sink -->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        *****
                    </div>
                    <div class="panel-body">
                        <div class="form-horizontal">
                            <div class="form-group">
                                <div class="col-sm-2">
                                    <label for="inspectionTaskCode">任务编号：</label>
                                    <input type="text" class="form-control" id="inspectionTaskCode"
                                           placeholder="请输入任务编号">
                                </div>


                                <div class="col-sm-2">
                                    <label for="lineCode">线路编号：</label>
                                    <input type="text" class="form-control" id="lineCode" placeholder="请输入任务编号">
                                </div>

                                <div class="col-sm-2">
                                    <label for="bugTypeName">缺陷类型*</label>
                                    <select class="form-control" id="bugTypeName" name="bugTypeName">
                                        <option value="">--请选择--</option>
                                        <option value="叉粱断裂">叉粱断裂</option>
                                        <option value="拦河线断裂">拦河线断裂</option>
                                        <option value="绝缘子爆破">绝缘子爆破</option>
                                        <option value="杆塔倾斜">杆塔倾斜</option>
                                        <option value="吊杆变形">吊杆变形</option>
                                        <option value="其他">其他</option>

                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <label for="bugLevelName">缺陷级别*</label>
                                    <select class="form-control" id="bugLevelName" name="bugLevelName">
                                        <option value="">--请选择--</option>
                                        <option value="一般">一般</option>
                                        <option value="严重">严重</option>
                                        <option value="紧急">紧急</option>
                                    </select>
                                </div>

                                <div class="col-sm-2">
                                    <label for="issuedTimestart">发现时间：</label>
                                    <input type="text" class="form-control" id="Findthetimestart" placeholder="请输入发现时间">
                                </div>
                                <div class="col-sm-2">
                                    <label for="issuedTimeend">：</label>
                                    <input type="text" class="form-control" id="Findthetimeend" placeholder="请输入发现时间">
                                </div>

                                <div class="col-sm-2">
                                    <label for="issuedTimestart">下发时间：</label>
                                    <input type="text" class="form-control" id="issuedTimestart" placeholder="请输入下发时间">
                                </div>
                                <div class="col-sm-2">
                                    <label for="issuedTimeend">：</label>
                                    <input type="text" class="form-control" id="issuedTimeend" placeholder="请输入下发时间">
                                </div>

                                <div class="col-sm-1">
                                    <label>*</label>
                                    <button class="btn btn-info col-sm-12" id="submitcx">查询</button>
                                </div>
                                <div class="col-sm-1">
                                    <label>*</label>
                                    <button disabled class="btn btn-info col-sm-12" id="print">打印</button>
                                </div>
                                <div class="col-sm-1">
                                    <label>*</label>
                                    <button disabled class="btn btn-info col-sm-12" id="ExportEXCEL">导出EXCEL</button>
                                </div>
                                <div class="col-sm-1">
                                    <label>*</label>
                                    <button class="btn btn-info col-sm-12" id="Empty">清空</button>
                                </div>
                            </div>
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>缺陷识别码</th>
                                    <th>线路编号</th>
                                    <th>杆塔编号</th>
                                    <th>缺陷级别</th>
                                    <th>缺陷类型</th>
                                    <th>发现人</th>
                                    <th>发现时间</th>
                                    <th>下发人</th>
                                    <th>下发时间</th>
                                    <th>完好率</th>
                                    <th>缺陷描述</th>
                                </tr>
                                </thead>
                                <tbody id="userlist"></tbody>
                            </table>
                            <ul class="pagination">
                                <li>
                                    <a href="">首页</a>
                                </li>
                                <li>
                                    <a href="">&laquo;</a>
                                </li>
                                <li>
                                    <a></a>
                                </li>
                                <li>
                                    <a href="">&raquo;</a>
                                </li>
                                <li>
                                    <a href="">末页</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- End  Kitchen Sink -->
            </div>

        </div>
    </div>
</div>
<!-- /. FOOTER  -->
<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
<script src="../assets/js/jquery.min.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="../assets/js/bootstrap.min.js"></script>

<script type="application/javascript">

    $(function () {
        getPage(1);
        $("#submitcx").click(function () {
            getPage(1);
        });
        //清空
        Empty();

    });

    //分页
    function getPage(pageNo) {
        var insTaskCode = $("#inspectionTaskCode").val().trim();
        var linCode = $("#lineCode").val().trim();
        var bugTypeName = $("#bugTypeName").val().trim();
        var bugLevelName = $("#bugLevelName").val().trim();
        var Findthetimestart = $("#Findthetimestart").val().trim();
        var Findthetimeend = $("#Findthetimeend").val().trim();
        var issdTimestart = $("#issuedTimestart").val().trim();
        var issdTimeend = $("#issuedTimeend").val().trim();
        $.ajax({
            url: "http://localhost:8080/inspectaskdetail/allInspectiontaskDetail",
            type: "get",
            data: {
                "currentPage": pageNo,
                "inspectionTaskCode": insTaskCode,
                "lineCode": linCode,
                "bugTypeName": bugTypeName,
                "bugLevelName": bugLevelName,
                "Findthetimestart": Findthetimestart,
                "Findthetimeend": Findthetimeend,
                "issuedTimestart": issdTimestart,
                "issuedTimeend": issdTimeend
            },
            dataType: "json",
            success: function (data) {
                if (data.status == 200 && data.obj.lists != null) {
                    console.log(data)
                    $("#userlist").html("");
                    var pageNum = data.obj.currPage;//当前页数
                    var totalPages = data.obj.totalPage;//总页数
                    var list = data.obj.lists;//每页的显示的数据
                    for (var i = 0; i < list.length; i++) {
                        var inspectaskdetailId = list[i].id;
                        var lineCode = list[i].lineCode;
                        var poleCode = list[i].poleCode;
                        var bugLevelName = list[i].bugLevelName;
                        var bugTypeName = list[i].bugTypeName;
                        var discovererName = list[i].discovererName;
                        var creationTime = list[i].creationTime;
                        var discoverTime = list[i].discoverTime;
                        var createdBy = list[i].createdBy;
                        var intactRate = list[i].intactRate;
                        var bugDesc = list[i].bugDesc;
                        var tr = "<tr>" +
                            "<td>" + inspectaskdetailId + "</td>" +
                            "<td>" + lineCode + "</td>" +
                            "<td>" + poleCode + "</td>" +
                            "<td>" + bugLevelName + "</td>" +
                            "<td>" + bugTypeName + "</td>" +
                            "<td>" + discovererName + "</td>" +
                            "<td>" + discoverTime + "</td>" +
                            "<td>" + createdBy + "</td>" +
                            "<td>" + discoverTime + "</td>" +

                            "<td>" + intactRate + "%" + "</td>" +
                            "<td>" + bugDesc + "</td>" +
                            "</tr>";

                        $("#userlist").append(tr);
                    }


                    /* 按钮换页 */
                    $(".pagination li:eq(0) a").attr("href", "javascript:getPage(1)");
                    $(".pagination li:eq(1) a").attr("href", "javascript:getPage(" + (pageNum - 1) + ")");
                    $(".pagination li:eq(3) a").attr("href", "javascript:getPage(" + (pageNum + 1) + ")");
                    $(".pagination li:eq(4) a").attr("href", "javascript:getPage(" + totalPages + ")");

                    if (pageNum <= 1) {
                        $(".pagination li:eq(1) a").attr("href", "javascript:getPage(1)");

                    } else if (pageNum >= totalPages) {
                        $(".pagination li:eq(3) a").attr("href", "javascript:getPage(" + totalPages + ")");
                    }
                    //当前页和总页数的显示

                    $(".pagination li:eq(2) a").html(pageNum + "/" + totalPages + "页");

                } else if (data.status == 500 && data.msg) {
                    alert(data.msg);
                }
            },
            error: function () {
                console.log("与后台断开连接！！！");
            }
        })
    }

    //清空条件
    function Empty() {
        $("#Empty").click(function () {
            $("#inspectionTaskCode").val("");
            $("#lineCode").val("");
            $("#Findthetimestart").val("");
            $("#Findthetimeend").val("");
            $("#issuedTimestart").val("");
            $("#bugLevelName").val("");
            $("#bugTypeName").val("");
            $("#issuedTimeend").val("");
        })

    }

    //详情
    function getDetails(inspeId, lineCodes) {
        sessionStorage.setItem("inspeId", inspeId);
        sessionStorage.setItem("lineCodes", lineCodes);
        window.location.href = "Inspec_view.html";
    }

    //添加
    function InspectionAdds() {
        window.location.href = "Inspec_add.html";
    }

    //修改
    function updateInspec(inspeId) {
        sessionStorage.setItem("inspeId", inspeId);
        window.location.href = "Inspec_update.html";
    }

    //取消
    function cancelInspec(inspeId) {
        if (confirm("确定取消此任务吗？？")) {
            var url = "http://localhost:8080/inspectask/" + inspeId;
            $.ajax({
                url: url,
                type: 'DELETE',
                dataType: "json",
                contentType: "application/json;charset=UTF-8",
                success: function (data) {
                    if (data.obj == 1) {
                        alert(data.msg)
                        window.location.href = 'FormuAndDist.html';
                    }
                }
            })
        }
    }

    //分配任务
    function distribution(inspeId, inspectionTaskCode) {
        //获取localStorage里的巡检员
        var xunjianyuan = localStorage.getItem(inspectionTaskCode);
        var inspector;
        if (xunjianyuan != null) {
            var inspector = prompt("请输入要分配的巡检员：", xunjianyuan);
        } else {
            var inspector = prompt("请输入要分配的巡检员：", "");
        }

        var url = "http://localhost:8080/inspectask/" + inspeId;
        $.ajax({
            url: url,
            type: 'PUT',
            dataType: "json",
            contentType: "application/json;charset=UTF-8",
            success: function (data) {
                if (data.obj == 1) {
                    alert(data.msg)
                    localStorage.setItem(inspectionTaskCode, inspector);
                    window.location.href = 'FormuAndDist.html';
                }
            }
        })
    }
</script>

</body>
</html>
